cmake_minimum_required(VERSION 2.6)

include_directories ("${PROJECT_BINARY_DIR}")
link_directories    ("${PROJECT_BINARY_DIR}")

set (LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}")

add_library(nth-plugin--add      SHARED "${CMAKE_CURRENT_LIST_DIR}/add.c")
add_library(nth-plugin--divide   SHARED "${CMAKE_CURRENT_LIST_DIR}/divide.c")
add_library(nth-plugin--multiply SHARED "${CMAKE_CURRENT_LIST_DIR}/multiply.c")
add_library(nth-plugin--subtract SHARED "${CMAKE_CURRENT_LIST_DIR}/subtract.c")

add_library(nth-plugin--results-dir SHARED "${CMAKE_CURRENT_LIST_DIR}/results-dir.c")

add_library(nth-plugin--number SHARED "${CMAKE_CURRENT_LIST_DIR}/number.c")
add_library(nth-plugin--file   SHARED "${CMAKE_CURRENT_LIST_DIR}/file.c")
add_library(nth-plugin--result SHARED "${CMAKE_CURRENT_LIST_DIR}/result.c")

add_library(nth-plugin--help    SHARED "${CMAKE_CURRENT_LIST_DIR}/help.c")
add_library(nth-plugin--version SHARED "${CMAKE_CURRENT_LIST_DIR}/version.c")
add_library(nth-plugin--view    SHARED "${CMAKE_CURRENT_LIST_DIR}/view.c")

target_link_libraries(nth-plugin--add      "nth-lib")
target_link_libraries(nth-plugin--divide   "nth-lib")
target_link_libraries(nth-plugin--multiply "nth-lib")
target_link_libraries(nth-plugin--subtract "nth-lib")

target_link_libraries(nth-plugin--results-dir "nth-lib")

target_link_libraries(nth-plugin--number "nth-lib")
target_link_libraries(nth-plugin--file   "nth-lib")
target_link_libraries(nth-plugin--result "nth-lib")

target_link_libraries(nth-plugin--help    "nth-lib")
target_link_libraries(nth-plugin--version "nth-lib")
target_link_libraries(nth-plugin--view    "nth-lib")

if (MSVC)

	function(ADD_EXPORTS_FILE TARGET EXPORTS_FILE)

		set (NEW_LINK_FLAGS "/def:${EXPORTS_FILE}")

		get_target_property(
			EXISTING_LINK_FLAGS
			${TARGET}
			LINK_FLAGS
		)

		if (EXISTING_LINK_FLAGS)
			set (NEW_LINK_FLAGS "${EXISTING_LINK_FLAGS} ${NEW_LINK_FLAGS}")
		endif()

		set_target_properties(
			${TARGET}
			PROPERTIES
			LINK_FLAGS
			"${NEW_LINK_FLAGS}"
		)

	endfunction()
	
	add_exports_file(nth-plugin--add      "${CMAKE_CURRENT_LIST_DIR}/add.def")
	add_exports_file(nth-plugin--divide   "${CMAKE_CURRENT_LIST_DIR}/divide.def")
	add_exports_file(nth-plugin--multiply "${CMAKE_CURRENT_LIST_DIR}/multiply.def")
	add_exports_file(nth-plugin--subtract "${CMAKE_CURRENT_LIST_DIR}/subtract.def")
	
	add_exports_file(nth-plugin--results-dir "${CMAKE_CURRENT_LIST_DIR}/results-dir.def")

	add_exports_file(nth-plugin--number "${CMAKE_CURRENT_LIST_DIR}/number.def")
	add_exports_file(nth-plugin--file   "${CMAKE_CURRENT_LIST_DIR}/file.def")
	add_exports_file(nth-plugin--result "${CMAKE_CURRENT_LIST_DIR}/result.def")

	add_exports_file(nth-plugin--help    "${CMAKE_CURRENT_LIST_DIR}/help.def")
	add_exports_file(nth-plugin--version "${CMAKE_CURRENT_LIST_DIR}/version.def")
	add_exports_file(nth-plugin--view    "${CMAKE_CURRENT_LIST_DIR}/view.def")
endif()

install(
	TARGETS
	nth-plugin--add
	nth-plugin--divide
	nth-plugin--multiply
	nth-plugin--subtract
	nth-plugin--results-dir
	nth-plugin--number
	nth-plugin--file
	nth-plugin--result
	nth-plugin--help
	nth-plugin--version
	nth-plugin--view
	DESTINATION "lib"
)

